<!-- 电子订阅 -->
<template>
  <div class="subs">
    <div class="wCen">
      <div class="formBox">
        <div class="formBox_l" :class="{hide:isMobile&&localeEn}">
          {{ $t("subscribe.label") }}
        </div>
        <div class="formBox_r">
          <el-form ref="form" :model="form" :rules="rules" inline label-width="0">
            <el-form-item prop="email"> <el-input v-model="form.email" :placeholder="$t('subscribe.placeholder')" clearable></el-input> </el-form-item
            ><el-button type="" @click="submitForm('form')" :class="{isMobileEn:isMobile&&localeEn}">{{ $t("subscribe.btn") }}</el-button>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { validateEmail } from "@/libs/validate";
import { submit } from "@/api/subscribe";
export default {
  props: {},
  data() {
    return {
      form: {
        email: "",
      },
      rules: {
        email: [
          {
            required: true,
            message: this.$t("subscribe.no-data-email"),
            trigger: "blur",
          },
          {
            validator: validateEmail,
            trigger: "blur",
          },
        ],
      },
    };
  },
  computed: {},
  mounted() {},
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.invoke(submit, this.form).then((res) => {
            if (res && res.code == 200) {
              this.$message.success(res.msg);
            }
          });
        } else {
          this.$message.warning(this.$t("subscribe.no-data-email"));
          return false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.subs {
  background-color: #659bfd;
  padding: 40px 0;
  box-sizing: border-box;
  .formBox {
    $wl: 50%;
    $wr: 50%;
    $w-btn: 300px;
    $h: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    &_l {
      color: #fff;
      font-size: 24px;
      width: $wl;
      flex-grow: 1;
    }
    &_r {
      position: relative;
      width: 100%;
      width: $wr;
      flex-grow: 1;
    }
    .hide{
      display: none;
    }
    .el-form-item__label {
      color: #fff;
    }
    :deep(.el-form) {
      &-item {
        margin-right: 0;
        width: 100%;
        margin-bottom: 0;
        &__content {
          width: 100%;
          line-height: 100%;
        }
        &__label {
          margin-right: 20px;
          font-size: 18px;
          color: #fff;
          font-weight: bold;
        }
        &__error {
          color: #fff;
          font-size: 16px;
        }
      }

      .el-input {
        font-size: 20px;
        &__inner {
          border-radius: 6px;
          width: 100%;
          padding-left: 20px;
          padding-right: calc(#{$w-btn} + 30px);
          height: $h;
          line-height: $h;
        }
        &__suffix {
          padding-right: calc(#{$w-btn});
          .el-icon-circle-close {
            font-size: 18px;
          }
        }
      }
      .el-button {
        border-radius: 6px;
        background-color: #d53b76;
        border: none;
        color: #fff;
        position: absolute;
        right: 0;
        width: $w-btn;
        height: $h;
        font-size: 24px;
      }
    }
  }
  @media (min-width: 1441px) and (max-width: 1750px) {
    @function scale($currentSize) {
      @return calc(#{$currentSize} * #{$global_scale_1600});
    }
    padding: scale(40px) 0;
    .formBox {
      $w-btn: scale(300px);
      $h: scale(60px);
      &_l {
        font-size: scale(24px);
      }
      :deep(.el-form) {
        &-item {
          &__label {
            margin-right: scale(20px);
            font-size: scale(18px);
          }
        }
        .el-input {
          font-size: scale(20px);
          &__inner {
            padding-left: scale(20px);
            padding-right: scale(calc(#{$w-btn} + 30px));
            height: $h;
            line-height: $h;
          }
        }
        .el-button {
          width: $w-btn;
          height: $h;
          font-size: scale(24px);
        }
      }
    }
  }
  @media screen and (min-width: 1281px) and (max-width: 1440px) {
    @function scale($currentSize) {
      @return calc(#{$currentSize} * #{$global_scale_1440});
    }
    padding: scale(40px) 0;
    .formBox {
      $w-btn: scale(310px);
      $h: scale(60px);
      &_l {
        font-size: scale(24px);
      }
      :deep(.el-form) {
        &-item {
          &__label {
            margin-right: scale(20px);
            font-size: scale(18px);
          }
        }
        .el-input {
          font-size: scale(20px);
          &__inner {
            padding-left: scale(20px);
            padding-right: scale(calc(#{$w-btn} + 30px));
            height: $h;
            line-height: $h;
          }
        }
        .el-button {
          width: $w-btn;
          height: $h;
          font-size: scale(24px);
        }
      }
    }
  }
  @media screen and (min-width: 768px) and (max-width: 1280px) {
    @function scale($currentSize) {
      @return calc(#{$currentSize} * #{$global_scale_1280});
    }
    padding: scale(40px) 0;
    .formBox {
      $w-btn: scale(320px);
      $h: scale(60px);
      &_l {
        font-size: scale(24px);
      }
      :deep(.el-form) {
        &-item {
          &__label {
            margin-right: scale(20px);
            font-size: scale(18px);
          }
        }
        .el-input {
          font-size: scale(20px);
          &__inner {
            padding-left: scale(20px);
            padding-right: scale(calc(#{$w-btn} + 30px));
            height: $h;
            line-height: $h;
          }
        }
        .el-button {
          width: $w-btn;
          height: $h;
          font-size: scale(24px);
        }
      }
    }
  }
  @media (max-width: 767px) {
    @function scale($currentSize) {
      @return calc(#{$currentSize} * #{$global_scale_750});
    }
    padding: scale(40px) 0;
    .formBox {
      $w-btn: 90px;
      $h: 30px;
      &_l {
        font-size: 14px;
        width: 18%;
      }
      &_r {
        flex-grow: 1;
      }
      :deep(.el-form) {
        &-item {
          &__label {
            margin-right: scale(20px);
            font-size: scale(18px);
          }
        }
        .el-input {
          font-size: 14px;
          &__inner {
            padding-left: 10px;
            padding-right: calc(#{$w-btn} + 10px);
            height: $h;
            line-height: $h;
          }
        }
        .el-button {
          width: $w-btn;
          height: $h;
          font-size: 14px;
          padding: 0;
          &.isMobileEn{
            width: 170px;
          }
        }
      }
    }
  }
}
</style>
